<?php

namespace Home\Model;

use Think\Model;

class RegionModel extends Model {

    /**
     * 取得某地区的所有子孙地区id
     */
    function get_descendant($id) {
        $ids = array($id);
        $ids_total = array();
        $this->_get_descendant($ids, $ids_total);
        return array_unique($ids_total);
    }
    function _get_descendant($ids, &$ids_total) {
        $childs=$this->where("parent_id " . db_create_in($ids))->getField('region_id',true);
        $ids_total = array_merge($ids_total, $ids);
        if (empty($childs)) {
            return;
        }
        $this->_get_descendant($childs, $ids_total);
    }
}

?>
